﻿using Castle.DynamicProxy;

using WS.EKA.Core.Attributes;
using WS.EKA.LogBridge;

namespace WS.EKA.Core.Interceptor
{
    public class DefaultInterceptor:IInterceptor
    {
        protected void PreIntercept(IInvocation invocation)
        {
            if (InterceptHelper.IsAttribute(typeof(LoggerAttribute), invocation))
            {
                Log.Info(string.Format("Before invoke method:{0}", invocation.Method));
            }
        }
        public void Intercept(IInvocation invocation)
        {
            PreIntercept(invocation);
            TansactionInterceptor.Proceed(invocation);
            PostIntercept(invocation);
        }
        protected void PostIntercept(IInvocation invocation)
        {
            if (InterceptHelper.IsAttribute(typeof(LoggerAttribute), invocation))
            {
                Log.Info(string.Format("After invoke method:{0}", invocation.Method));
            }
        }
    }
}
